package com.hanserwei.mydemo.currying;

public class CarryingDemo01 {
    public static void main(String[] args) {
        // 两个参数的函数对象
        F2 f = (a, b) -> a + b;
        System.out.println(f.op(10, 20));
        /*改造:函数对象每次只能传入一个参数，要实现加法运算。将函数对象拆分成两个函数对象
         * (a) -> 返回另一个函数对象
         *           (b) -> a + b
         * */
        Fa fa = (a) -> (b) -> a + b;
        Fb fb = fa.op(10);
        int result = fb.op(20);
        System.out.println(result);
    }

    @FunctionalInterface
    interface F2 {
        int op(int a, int b);
    }

    @FunctionalInterface
    interface Fa {
        Fb op(int a);
    }

    @FunctionalInterface
    interface Fb {
        int op(int b);
    }
}
